Well-Formed Documents

As you have seen so far, you can create very complex content models using XML.  If your document is not well-formed, XML processors are not going to be able to use them.  The XML specification goes so far as to say that an entity is not an XML document until it is well-formed.  

There are rules to document well-formedness, many of which you have already encountered.  A document is considered well-formed if:

It contains one or more elements.

It has just one element (the root element) that contains all other elements.

The elements contained within the root are properly nested inside each other (synchronous structures).

Element names are correctly matched by name and case.

The names of attributes only appear once in a given element’s start tag.

Attribute values are enclosed in either single or double quotes.

Attribute values do not reference external entities, either directly or indirectly.

The replacement text for any entity referenced in an attribute does not contain a less-than (<) character (it can contain the predefined entity &lt;).

All entities are declared before they are used.

No entity references contain the name of an unparsed entity.

The logical and physical structures are properly nested.

If an XML processor encounters a violation against these rules of well-formedness in a document, it will stop processing the document and generate one or more fatal errors.

This is very different than the HTML standard and the way that browsers support HTML.  Browsers are very lenient and try to make sense out of everything that it is given.  It is rumored that 75% of the code in both Internet Explorer and Netscape Navigator exists to handle bad and/or invalid HTML code!